<?php
session_start();

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Schools Management System</title>
<meta http-equiv="Content-Language" content="English" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="../style.css" media="screen" />

</head>
<body>
<?php
include_once '../Login/databaseconnection.php';

if(!loggedin())
{
require_once '../index.php';
}
   
   else
   {
   if(isset($_POST['SaveChanges']))
   {
 
   require_once 'UPP.php';
   }
    $P_Id="";
	   $S_Id="";
	   $year="";
   if(isset($_POST['Edit_This']))
	   {
	   $P_Id=$_POST['Pro_Id'];
	   $S_Id=$_POST['Sch_Id'];
	   $year=$_POST['Year'];
	   
	$_SESSION['P_Id']=$P_Id;
	  $_SESSION['S_Id']=$S_Id;
	  $_SESSION['year']=$year;
 if( $P_Id=="Select One"||$S_Id=="Select One"||$year=="Select One")
	   {
		    
	$_SESSION['errorin1']="Please select the Programme id,School id and Year!";

	   }
	   if($P_Id!="Select One"||$S_Id!="Select One"||$year!="Select One")
	   {
	   $result=mysql_query("SELECT * FROM programmes WHERE Programme_Id='$P_Id' AND School_Id='$S_Id' AND Year='$year'");
	   if(mysql_num_rows($result)==0)
   {
	   $_SESSION['errornorow']="Very sorry there is no result,Please check your input and try again!";
   }
	   }
	   }
   ?>
   <div id="wrap">

<div id="header"><table width="1239" border="0">
  <tr>
    <td width="866" height="119" rowspan="2"><h1 class="heaaderte"><font color="#996699" style="text-shadow:#969" size="+6">Schools Management System</font></h1></td>
    <td width="110" height="88">&nbsp;</td>
    <td width="161">&nbsp;</td>
    <td width="84">&nbsp;</td>
  </tr>
  <tr>
    <td height="21">&nbsp;</td>
    <td>
	<?Php
	//$First_Name=$_SESSION['First_Name'];
    //$_SESSION['Last_Name']=$Last_Name;
	  if(isset($_SESSION['First_Name']))
	  
{
      echo "Hi,". $_SESSION['First_Name']." ".$_SESSION['Last_Name'];
}
?></td>
    <td><a href="../Logout.php" class="logout">Logout</a></td>
  </tr>
  </table>
</div>

<div id="menu1_bg">
		<div id="menu1">
			
	
	
				<ul>
				<li><a href="../index.php"><font color="#CCCC66" style="text-shadow:#969" size="+1">Home</font></a></li>
				<li><a href="../Schools/Schools.php"><font color="#CCCC66" style="text-shadow:#969" size="+1">Schools</font></a></li>
				<li><a href="../Teachers/teachers.php"><font color="#CCCC66" style="text-shadow:#969" size="+1">Teachers</font></a></li>
				<li><a href="../Lab/Labs.php"><font color="#CCCC66" style="text-shadow:#969" size="+1">Labs</font></a></li>
				<li><a href="../Resources/Resources.php"><font color="#CCCC66" style="text-shadow:#969" size="+1">Resources</font></a></li>
                <li><a href="#"><font color="#CCCC66" style="text-shadow:#969" size="+1">Resource Team</font></a></li>
                         <li><a href="Programmes.php" class="active"><font color="#CCCC66" style="text-shadow:#969" size="+1">Programmes</font></a></li>
                                  <li><a href="../Competition/Competition.php"><font color="#CCCC66" style="text-shadow:#969" size="+1">Competitions</font></a></li>
                 <li></li>
			</ul>
	</div>
  </div>
<div class="left">
  
<div class="articles"><form action="#" method="POST">
  <table width="440" border="0">
    <tr>
      <th colspan="4"  scope="row"><?php
		if(isset($_POST['Edit_This'])||isset($_POST['SaveChanges']))
{
	if($_SESSION['error']!=" ")
	{
		echo $_SESSION['error'];
		unset($_SESSION['error']);
	}
	if($_SESSION['errorin']!=" ")
	{
		echo $_SESSION['errorin'];
		unset($_SESSION['errorin']);
	}
	if($_SESSION['errorin1']!=" ")
	{
		echo $_SESSION['errorin1'];
		unset($_SESSION['errorin1']);
	}
	if($_SESSION['errornorow']!=" ")
	{
		echo $_SESSION['errornorow'];
		unset($_SESSION['errornorow']);
	}
	
}
		?>
      </th>
      </tr>
    <tr>
      <th width="44"  scope="row">&nbsp;</th>
      <th width="124"  scope="row">Programme Id:</th>
      <td colspan="2"><select name="Pro_Id" id="select">
	  <?php
	  
	  if(isset($_POST['Edit_This']))
	  {
	echo '<option value="'.$P_Id.'">'.$P_Id.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
   
      <?php
	  
	  $pro=mysql_query("SELECT DISTINCT(Programme_Id) FROM programmes");
	  
  while($row=mysql_fetch_array($pro))
  {
	  $p_id=$row['Programme_Id'];

	  echo '<option value="'.$p_id.'">'.$p_id.'</option>';
  }
	  ?>
     
      </select></td>
    </tr>
    <tr>
      <th height="31" scope="row">&nbsp;</th>
      <th scope="row">School Id:</th>
      <td colspan="2"><select name="Sch_Id" id="select">
	   <?php
	  
	  if(isset($_POST['Edit_This']))
	  {
	echo '<option value="'.$S_Id.'">'.$S_Id.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
        <?php
		
	  $pro=mysql_query("SELECT DISTINCT(School_Id) FROM programmes");
	  
  while($row=mysql_fetch_array($pro))
  {
	  $Sch_Id=$row['School_Id'];

	  echo '<option value="'.$Sch_Id.'">'.$Sch_Id.'</option>';
  }
	  ?>
      </select></td>
    </tr>
    <tr>
      <th height="26" scope="row">&nbsp;</th>
      <th scope="row">Year:</th>
      <td colspan="2"><select name="Year" id="select">
	 <?php
	  
	  if(isset($_POST['Edit_This']))
	  {
	echo '<option value="'.$year.'">'.$year.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
        <?php
	  $pro=mysql_query("SELECT DISTINCT(Year) FROM programmes");
	  
  while($row=mysql_fetch_array($pro))
  {
	 $year=$row['Year'];

	  echo '<option value="'.$year.'">'.$year.'</option>';
  }
	  ?>
      </select></td>
    </tr>
    <tr>
      <th height="24" scope="row">&nbsp;</th>
      <th scope="row">&nbsp;</th>
      <td width="66">&nbsp;</td>
      <td width="188"><a href="UpdateProSch.php">Reset</a>|
        <input name="Edit_This" align="middle" type="submit" value="Edit this" /></td>
    </tr>
  </table>
  <br/>
  <br/>
  
</form>
<form action="#" method="POST">
    <?php 
if(isset($_POST['Edit_This']))
		{

	   $P_Id=$_POST['Pro_Id'];
	   $S_Id=$_POST['Sch_Id'];
	  $year=$_POST['Year'];
	   if( $P_Id!="Select One"&&$S_Id!="Select One"&&$year!="Select One")
	   {
   $result=mysql_query("SELECT * FROM programmes WHERE Programme_Id='$P_Id' AND School_Id='$S_Id' AND Year='$year'");
  echo '<table width="354" border="0">';
 while($row=mysql_fetch_array($result))
  {
    
$p_name=$row['Programme_Name'];
$no_stu=$row['No_Of_Students'];
$te_in_trai=$row['Teachers_In_Training'];
$tra_tea=$row['Trained_Teachers'];
$Pro_Id=$row['Programme_Id'];
$Sch_Id=$row['School_Id'];
$Year=$row['Year'];

?>
   <?php
   echo '<tr>';
        echo '<th width="200" height="29" scope="row" bgcolor="#936">';
		echo "Programme Id:";
		echo '</th>';
        echo '<td width="144">';
		echo '<div contenteditable>';
		echo "<input type='text' name='Pro_Id' value='$Pro_Id'>";
		echo '</div>';
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="29" scope="row" bgcolor="#936">';
		echo "School Id:";
		echo '</th>';
        echo '<td>';
		echo '<div contenteditable>';
		echo "<input type='text' name='Sch_Id' value='$Sch_Id'>";
		echo '</div>';
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th width="200" height="29" scope="row" bgcolor="#936">';
		echo "Year:";
		echo '</th>';
        echo '<td width="144">';
		echo '<div contenteditable>';
		echo "<input type='text' name='Year' value='$Year'>";
		echo '</div>';
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th width="200" height="29" scope="row" bgcolor="#936">';
		echo "Programme Name:";
		echo '</th>';
        echo '<td width="144">';
		echo '<div contenteditable>';
		echo "<input type='text' name='Programme_Name' value='$p_name'>";
		echo '</div>';
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="29" scope="row" bgcolor="#936">';
		echo "Number of students:";
		echo '</th>';
        echo '<td>';
		echo '<div contenteditable>';
		echo "<input type='text' name='No_Of_Students' value='$no_stu'>";
		echo '</div>';
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="29" scope="row" bgcolor="#936">';
		echo "Number of teachers in training:";
		echo '</th>';
        echo '<td>';
		echo '<div contenteditable>';
		echo "<input type='text' name='Teachers_In_Training' value='$te_in_trai'>";
		echo '</div>';
		echo '</td>';
		 echo '</tr>';
      echo '<tr>';
        echo '<th height="29" scope="row" bgcolor="#936">';
		echo "Number of trained teachers :";
		echo '</th>';
       echo '<td>';
	   echo '<div contenteditable>';
	   echo "<input type='text' name='Trained_Teachers' value='$tra_tea'>";
	   echo '</div>';
	   echo '</td>';
      echo '</tr>';
     echo '<tr>';
       echo '<th height="29" scope="row" bgcolor="#936">';
	   echo "Availability of books:"; 
	    echo '</th>';
       echo '<td bgcolor="#936">';
	  
	   if($row['Availability_Books']=="Yes")
		   {
           echo '<input type="radio" name="Avai_Book" value="Yes" checked="checked"/>';
		    echo "Yes";
			echo '<input type="radio" name="Avai_Book" value="No"/>';
		    echo "No";
		   }
               
           echo "<br />";
		   if($row['Availability_Books']=="No")
		   {
			   echo '<input type="radio" name="Avai_Book" value="Yes"/>';
		    echo "Yes";
           echo '<input type="radio" name="Avai_Book" value="No" checked="checked"/>';
		    echo "No";
		   }
		 
		   
           
			  echo "<br />";
			  
       echo '</td>';
     echo '</tr>';
     echo '<tr>';
       echo '<th height="44" scope="row" bgcolor="#936">';
	   echo "Availability of teachers guides:"; 
	    echo '</th>';
       echo '<td bgcolor="#936">';
	   
	    if($row['Availability_Tguides']=="Yes")
		   {
           echo '<input type="radio" name="Avai_Tea_Gui" value="Yes" checked="checked"/>';
		    echo "Yes";
			echo '<input type="radio" name="Avai_Tea_Gui" value="No"/>';
		    echo "No";
		   }
               
           echo "<br />";
		   if($row['Availability_Tguides']=="No")
		   {
			   echo '<input type="radio" name="Avai_Tea_Gui" value="Yes"/>';
		    echo "Yes";
           echo '<input type="radio" name="Avai_Tea_Gui" value="No" checked="checked"/>';
		    echo "No";
		   }
		 
			  echo '</td>';
     echo '</tr>';

   }
   echo '</table>';
   echo "<br/>";
   echo '<input name="SaveChanges" align="middle" type="submit" value="Save changes" />';	
   }
   
 }
	   
	   ?>
       </form>
   
</div>
</div>

<div class="rightmenu"> 
<h1>PROGRAMMES</h1><br />
<table width="220" border="0">
  <tr>
    <td width="210" height="41"><a href="RegPro.php">Add New Programme</a></td>
   

  </tr>
  <tr>
    <td height="41"><a href="SearchPro.php">Search a Programme</a></td>
    
    
  </tr>
  <tr>
    <td height="41"><a href="SearchProSch.php">Search Programmes for a school</a></td>

    
  </tr>
  <tr>
    <td height="41"><a href="UpdateProSch.php">Update a Programme of a School</a></td>
 
    
  </tr>
  <tr>
    <td height="41"><a href="DelPro.php">Delete a Programme of a School</a></td>
    
    
  </tr>
  <tr>
    <td height="41"><a href="Viewall.php">View All</a></td>
   

  </tr>
</table>
</div>
 
 <div style="clear: both;"> </div>


<div id="footer"><table width="1236" height="38" border="0">
    <tr>
      <td width="904" height="34">Schools Managemrnt System &copy; 2012 </td>
      <td width="50"><strong><a href="#" class="active">Home</a><a href="#"></a></strong>|</td>
      <td width="80"><strong><a href="#">Contact us</a></strong>|</td>
      <td width="40"><a href="http//www.facebook.com"><img src="../images/facebook1.png" width="38" height="38"/></a></td>
      <td width="38"><a href="http//twitter.com"><img src="../Images/twitter.png" width="38" height="38"/></a></td>
      <td width="36"><a href="http//www.google.lk"><img src="../Images/google.png" width="38" height="38"/></a><a href=""http="http"//www.yahoo.com""></a></td>
      <td width="58"><a href=""http="http"//www.yahoo.com""><img src="../Images/yahoo.png" alt="" width="38" height="38"/></a></td>
    </tr>
  </table>
</div>
</div>
<?php

}
?>
</body>
</html>